package wordcount

import (
	"regexp"
	"strings"
)

const testVersion = 3

// Use this return type.
type Frequency map[string]int

// RegLetters
var RegLetters = regexp.MustCompile(`[a-zA-Z0-9\']+`)

// Just implement the function.
func WordCount(phrase string) Frequency {
	phrase = strings.ToLower(phrase)
	phrases := RegLetters.FindAllString(phrase, -1)
	frequency := make(Frequency)

	t := ""
	for i := 0; i < len(phrases); i++ {
		t = strings.Trim(phrases[i], "'")
		if _, ok := frequency[t]; ok {
			frequency[t] += 1
		} else {
			frequency[t] = 1
		}
	}

	return frequency
}
